package com.xxxx.server.controller;


import com.xxxx.server.pojo.Position;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IPositionService;
import com.xxxx.server.service.impl.PositionServiceImpl;
import io.swagger.annotations.ApiOperation;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2022-01-12
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {

    @Autowired
    private IPositionService positionService;
    @ApiOperation("获取所有职位")
    @GetMapping("/getAllPositions")
    public RespBean getAllPositions(){
        List<Position> positions=positionService.list();
        return  RespBean.success("获取成功",positions);
    }
    @ApiOperation("通过Id获取职位")
    @GetMapping("/getAllPositionById/{id}")
    public  RespBean getPositionById(@PathVariable Integer id)
    {
        Position position=positionService.getById(id);
        return  RespBean.success("获取成功",position);
    }
    @ApiOperation("增加职位")
    @PostMapping("/addPosition")
    public  RespBean addPosition(@RequestBody Position position)
    {
        position.setCreateDate(LocalDateTime.now());
        if(positionService.save(position))
            return RespBean.success("添加成功");
        else  return RespBean.error("添加失败");

    }
    @ApiOperation("修改职位")
    @PutMapping("/updatePosition")
    public  RespBean updatePosition(@RequestBody Position position)
    {
        if(positionService.updateById(position))
            return RespBean.success("修改成功");
        else  return RespBean.error("修改失败");
    }
    @ApiOperation("通过id删除")
    @DeleteMapping("/deletePositionById/{id}")
    public  RespBean deletePositionById(@PathVariable Integer id)
    {
        if(positionService.removeById(id))
            return RespBean.success("删除成功");
        else  return RespBean.error("删除失败");
    }
    @ApiOperation("通过id批量删除")
    @DeleteMapping("/deletePositionById/")
    public  RespBean deletePositionById(Integer[] ids)
    {
        if(positionService.removeByIds(Arrays.asList(ids)))
            return RespBean.success("删除成功");
        else  return RespBean.error("删除失败");
    }
}
